#include<bits/stdc++.h>
#define int long long
#define N 1000005
using namespace std;
int n,r;
int fac[N];
int s;
int vis[N],sum[N],a[N];
void dfs(int x){
	if(x>n){
		r--;
		if(!r){
			for(int i=1;i<=n;i++) printf("%lld ",a[i]);
			exit(0);
		}
		return;
	}
	for(int i=1;i<=n;i++){
		if(vis[i]) continue;
		if(x!=1&&i>=sum[x-1]) continue;
		sum[x]=sum[x-1]+i;
		a[x]=i;vis[i]=1;
		dfs(x+1);
		vis[i]=0;
	}
}
void sol1(int o){
	printf("3 1 2 ");
	for(int i=4;i<=n-o;i++) printf("%lld ",i);
	vector<int> f;
	for(int i=n-o+1;i<=n;i++) f.push_back(i);
	for(int i=o;i>=1;i--){
		int id=0;
		vector<int> g;
		for(int j=0;j<(int)f.size();j++){
			if(r-fac[i-1]>0) id++,r-=fac[i-1];
			else break;
		}
		printf("%lld ",f[id]);
		for(int j=0;j<(int)f.size();j++) if(j!=id) g.push_back(f[j]);
		swap(f,g);
	}
}
void DFS(int x){
	if(x>n){
		r--;
		if(!r){
			for(int i=1;i<=n;i++) printf("%lld ",a[i]);
			exit(0);
		}
		return;
	}
	for(int i=1;i<=n;i++){
		if(vis[i]) continue;
		if(x!=1&&i>=sum[x-1]) continue;
		sum[x]=sum[x-1]+i;
		if(sum[x]>n&&n-x<=20&&x!=n&&r>fac[n-x]){
			r-=fac[n-x];
			continue;
		}
		a[x]=i;
		vis[i]=1;
		DFS(x+1);
		vis[i]=0;
	}
}
signed main(){
	freopen("permutation.in","r",stdin);
	freopen("permutation.out","w",stdout);
	scanf("%lld %lld",&n,&r);
	if(n<=8){dfs(1);return 0;}
	fac[0]=1;
	for(int i=1;i<=20;i++) fac[i]=fac[i-1]*i;
	int p=0;
	for(int i=1;i<=n;i++){
		s+=i;p=i;
		if(s>n) break;
	}
	if(n-p>=20){sol1(20);return 0;}
	DFS(1);
	return 0;
}